@include('admin.public.head')

<style type="text/css">

    .inner_btn {
        background: #19a97b;
        color: white;
        padding: 5px 8px;
        border-radius: 2px;
    }
</style>

<div class="ibox-title">
    <h5>用户预约</h5>
</div>

<div class="ibox-content">
    <div class="row">
        <div class="col-sm-12 pull-right m-b-xs">
            <form action="">

                <input type="hidden" name="class_base_info_id" value="{{$class_base_info_id??0}}}">

                <div class="col-sm-1  m-b-xs text-center pull-right">
                    <button type="submit" class="btn btn-sm btn-primary">搜索</button> </span>
                    <a class="btn btn-primary btn-sm dropdown-toggle" onclick="window.location.reload();" href="javascript:void(0)">刷新頁面
                    </a>
                </div>

                <div class="col-sm-1 text-center pull-right">
                    <input type="text" name="sear_value" value="{{$sear_value}}" placeholder="用戶名稱/用户电话/用戶編號" class="input form-control">
                </div>

                <div class="col-sm-1 text-center pull-right">
                    <select class="form-control" name="is_tutoring" >
                        <option value="">预约类型</option>
                        <option value="1" @if($is_tutoring == 1) selected="selected" @endif>补课预约</option>
                        <option value="2" @if($is_tutoring == 2) selected="selected" @endif>单节课预约</option>
                    </select>
                </div>

                <div class="col-sm-1 text-center pull-right">
                    <select class="form-control" name="subscribe_status" >
                        <option value="">状态</option>
                        <option value="1" @if($subscribe_status == 1) selected="selected" @endif>排队中</option>
                        <option value="2" @if($subscribe_status == 2) selected="selected" @endif>预约成功</option>
                        <option value="3" @if($subscribe_status == 3) selected="selected" @endif>预约失败</option>
                        <option value="4" @if($subscribe_status == 4) selected="selected" @endif>预约取消</option>
                        <option value="5" @if($subscribe_status == 5) selected="selected" @endif>上课完成</option>
                        <option value="6" @if($subscribe_status == 6) selected="selected" @endif>請假</option>
                        <option value="7" @if($subscribe_status == 7) selected="selected" @endif>已选择补课</option>
                    </select>
                </div>

                @include('admin.public.store.where_select')

                @include('admin.public.class_base_info.where_classroom_teacher_classbase')

                @include('admin.public.common.where_time_input')

            </form>
        </div>
    </div>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>用戶頭像</th>
            <th>用戶編號</th>
            <th>用戶名稱</th>
            <th>用戶電話</th>
            <th>課名稱</th>
            <th>门店名称</th>
            <th>课室编号</th>
            <th>教师名稱</th>
            <th>上课时间</th>
            <th>下課時間</th>
            <th>预约类型</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody>
        @foreach ($result as $v)
            <tr>
                <td>
                    <img src="{{$v->user->head_img??''}}" style="width: 132px;height: 132px">
                </td>
                <td>
                    {{$v->user->user_number??''}}
                </td>
                <td>
                    {{$v->user->nickname??''}}
                </td>
                <td>
                    {{$v->user->phone??''}}
                </td>
                <td>
                    {{$v->class_name??''}}
                </td>
                <td>{{$v->store_name??''}}</td>
                <td>{{$v->class_classroom_name??''}}</td>
                <td>{{$v->teacher_name??''}}</td>
                <td>{{$v->class_time??''}}</td>
                <td>{{$v->end_time??''}}</td>
                <td>
                    @if($v->is_tutoring == 1) 补课预约 @endif
                    @if($v->is_tutoring == 2) 单节课预约 @endif
                </td>
                <td>
                    @if($v->subscribe_status === 1)
                        排队中
                    @elseif($v->subscribe_status == 2)
                        预约成功
                    @elseif($v->subscribe_status == 3)
                        预约失败
                    @elseif($v->subscribe_status == 4)
                        预约取消
                    @elseif($v->subscribe_status == 5)
                        上课完成
                    @elseif($v->subscribe_status == 6)
                        请假
                    @endif
                </td>

               <td>
                   @if($v->subscribe_status === 1)
                        <div class="btn-group">
                            <a  class="btn btn-primary btn-sm dropdown-toggle" onclick="return_queue($(this))" url="/user_return_queue/{{$v->id}}" href="javascript:void(0)">退出排隊
                            </a>&nbsp;&nbsp;
                        </div>
                   @endif
                   @if($v->subscribe_status === 2)
                       <div class="btn-group">
                           <a  class="btn btn-primary btn-sm dropdown-toggle" onclick="cancel_appointment($(this))" url="/cancel_appointment/{{$v->id}}" href="javascript:void(0)">取消预约
                           </a>&nbsp;&nbsp;
                       </div>
                       <div class="btn-group">
                           <a  class="btn btn-primary btn-sm dropdown-toggle" onclick="save_time($(this))" url="/class_sign_in/{{$v->id}}" href="javascript:void(0)">签到
                           </a>&nbsp;&nbsp;
                       </div>
                   @endif
                </td>
            </tr>
        @endforeach
        </tbody>
        {{ $result->appends(Request::except ('page'))->links() }}
    </table>
    {{ $result->appends(Request::except ('page'))->links() }}
</div>
<script>
    function return_queue(obj){
        var url = obj.attr('url');
        var title =  "你確定退出排隊";
        var botton =  "退出";
        var result =  "退出成功";

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: botton,
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                success: function(data) {

                    if(data.status == true) {
                        var swal_json = {
                            title: result,
                            type: "success"
                        }
                    }else{
                        var swal_json = {
                            title: data.message,
                            type: "error"
                        }
                    }

                    swal(swal_json,function(isConfirm){
                        window.location.reload();
                    });

                }
            });

        });
    }

    function cancel_appointment(obj){
        var url = obj.attr('url');
        var title =  "你確定取消預約";
        var botton =  "取消";
        var result =  "取消成功";

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: botton,
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                success: function(data) {

                    if(data.status == true) {
                        var swal_json = {
                            title: result,
                            type: "success"
                        }
                    }else{
                        var swal_json = {
                            title: data.message,
                            type: "error"
                        }
                    }

                    swal(swal_json,function(isConfirm){
                        window.location.reload();
                    });

                }
            });

        });
    }

    function save_time(obj){
        var url = obj.attr('url');
        var title =  "你確定签到";
        var botton =  "签到";
        var result =  "签到成功";

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: botton,
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                success: function(data) {

                    if(data.status == true) {
                        var swal_json = {
                            title: result,
                            type: "success"
                        }
                    }else{
                        var swal_json = {
                            title: data.message,
                            type: "error"
                        }
                    }

                    swal(swal_json,function(isConfirm){
                        window.location.reload();
                    });

                }
            });

        });
    }
</script>
